<!DOCTYPE html>
<html lang="en">

  <head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>斐波那契数列</title>
  </head>

  <body>

  </body>
  <script>
    function f(n) {
      var sum = 1;
      for (let i = 0; i < n; i++) {
        if (i == 0) {
          var num1 = 0;
        } else if (i == 1) {
          var num2 = 1;
        } else {
          sum = num1 + num2;
          num1 = num2;
          num2 = sum;
        }
      }
      return sum
    }
    console.log(f(6));//5
  </script>

</html>